Skip to main content
This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

HCL Notes/Domino 8.5 Forum (includes Notes Traveler)

Previous Next

You may want to clean up your code a little...

A few hints:
Put all the variable declarations in the beginning. You have one right in the middle of your code (FullPath1), which you don't even use.

Remove variables you don't use. FullPath1, s, filesys, path, view and a bunch more are never used.

Declare the variables in a consistent way.
I always declare the Domino objects first, starting with all UI classes, then the backend classes.
Then I declare any custom classes, and finally regular variables in the order they are being used.
I know some prefer to sort the variables alphabetically, but I like to be able to judge where in the code the assignment/usage is based on the sort order.

Try to be consistent with capitalization of variables. I normally use all lower case for variables read from fields/notes items or returned by Lotusscript functions, and CamelCase for other variables.

If you can, group object assignments together:
Set uidoc = ws.CurrentDocument
Set doc = uidoc.document

I also notice that yoru are reading values from teh document using both uidoc.FieldGetText and doc.GetItemValues. Try to be consistent.
You also overwrite the existing field "FileName" (which is a text field initially) with a RichText item... Don't do that, create a new RichText field called "Attachment" instead. Then you would use GetFirstItem() to get a reference to it.

You are also passing arguments to EmbedObject that shold not be used with attachments (the last argument).

All that will make the code much easier to read.
Below is your code cleaned up.

Sub Initialize
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim filepath As String
Dim filename As String

'*** Save currenly open document
Set uidoc = ws.CurrentDocument
Call uidoc.Save

'*** Get backend document and read field values
Set doc = uidoc.document
filepath = doc.GetItemValue("FullPath")(0) ' Path must end with /
filename = doc.GetItemValue("FileName")(0)

'*** Create a new rich text field called 'Attachment' and save doc
'*** Use GetFirstItem() if the field already exists in document
Set rtitem = New NotesRichTextItem(doc, "Attachment")
Call rtitem.EmbedObject(EMBED_ATTACHMENT,"", filepath + filename)
Call doc.Save(True,True)

End Sub

Don't you agree, much easier to read and follow the code?


Feedback response number WEBB94WM33 created by ~Dan Kikiterobu on 02/14/2013

Error in Code (~Howard Nimnuko... 13.Feb.13)
. . I think the field Fullpath is not a... (~Denise Lopnipl... 13.Feb.13)
. . . . Error in Code (~Howard Nimnuko... 14.Feb.13)
. . . . . . where is this code running?? (~Denise Lopnipl... 14.Feb.13)
. . . . . . . . Reply (~Howard Nimnuko... 14.Feb.13)
. . Try declaring rtitem as NotesRichTe... (~August Cispone... 13.Feb.13)
. . Fullpath not Filename (I think) (~Justin Chugero... 14.Feb.13)
. . . . Still, Problem exists (~Howard Nimnuko... 14.Feb.13)
. . . . . . code (~Denise Lopnipl... 14.Feb.13)
. . . . . . . . Thank You All...It is working.. (~Howard Nimnuko... 14.Feb.13)
. . . . . . . . . . You may want to clean up your code ... (~Dan Kikiterobu... 14.Feb.13)
. . . . . . . . . . . . Thank You Karl......... (~Howard Nimnuko... 15.Feb.13)
. . . . . . . . . . . . . . I am curious... (~Dan Kikiterobu... 15.Feb.13)
. . . . . . . . . . . . . . . . No (~Howard Nimnuko... 27.Mar.13)




Printer-friendly

Search this forum

Member Tools


RSS Feeds

 RSS feedsRSS
All forum posts RSS
All main topics RSS